home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / show / jpgagasr.lha / ppm2aga / ppm2AGA.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  5.7 KB  |  243 lines

  1. /* ppm2AGA main module                */
  2. /* written 1993-94 by Günther Röhrich */
  3. /* This is version 1.3                */
  4.  
  5. #include <clib/exec_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/graphics_protos.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <graphics/gfxbase.h>
  10. #include <libraries/iffparse.h>
  11. #include <iffp/ilbmapp.h>
  12. #include <dos/dos.h>
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16.  
  17. #ifndef __GNUC__
  18. #include <pragmas/intuition_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #endif
  22.  
  23. #include "ppm2AGA.h"
  24.  
  25. #ifdef __GNUC__
  26. #include <signal.h>
  27. #define MYSTRCMP strcasecmp
  28. #define MYSTRNCMP strncasecmp
  29. #else
  30. #define MYSTRCMP strcmp
  31. #define MYSTRNCMP strncmp
  32. #endif
  33.  
  34.  
  35. /* externals used by this module */
  36.  
  37. extern int ppm2ilbm(char *PPMfile, ULONG Mode, int NumPlanes, ULONG MaxMem); 
  38. #ifdef AZTEC_C
  39. extern int Enable_Abort; /* Needed to disable default CTRL-C handling */
  40. #endif
  41.  
  42. /* globals defined in this module */
  43.  
  44. char  *ver = "\0$VER: ppm2AGA 1.3 (4.6.94)";
  45. struct Library *IntuitionBase = NULL;
  46. struct Library *GfxBase = NULL;
  47. struct Library *IFFParseBase = NULL;
  48. int floyd=0; /* indicates if FS-dithering should be used */
  49. char *ILBMfile;
  50. int ExactColor=0; /* indicates if shifting colors is allowed */
  51. int GfxEnable=0;  /* indicate if Gfx is enabled */
  52. int VGAenable=0;  /* indicate VGA-mode */
  53. int jpegAGA=0;    
  54.  
  55. void PLError(char *ErrorString); /* prints the message, cleans up and quits */
  56. void PLExit(int returnvalue); /* cleans up and quits */
  57. void pm_message(char* format, ... );
  58. int AbortCheck(void);
  59. void PLProgress(ULONG Value, ULONG MaxValue);
  60.  
  61.  
  62. #ifdef __GNUC__
  63. int GCCabort=0;
  64. /* this is called when CTRL-C occurs */
  65. void GCCAbortHandler(void)
  66. {
  67.   GCCabort=1;
  68. }
  69. #endif
  70.  
  71. void PLUsage(void)
  72. {
  73.  PLError("Usage: ppm2AGA infile outfile [switches]\n"
  74.          "switches: -HAM8    use HAM8-conversion (default)\n"
  75.          "          -HAM6    use HAM6-conversion\n"
  76.          "          -CMAPn   use COLORMAP conversion with n planes\n"
  77.          "          -E       use exact colors (only COLORMAP mode)\n"
  78.          "          -FS      enable FS-dithering (not available for HAM8)\n"
  79.          "          -Mx      load pictures up to x size into memory\n"
  80.          "          -2       enable 2-pass processing for HAM mode\n" 
  81.          "          -D       display picture during processing\n"
  82.          "          -VGA     use VGA screenmode\n"
  83.          "          -jpegAGA create colormap file for jpegAGA\n");
  84. }
  85.  
  86.  
  87. main(int argc, char *argv[])
  88. {
  89.  int Error;
  90.  int i;
  91.  ULONG Mode=HAM8;
  92.  int NumPlanes = 63;
  93.  int Pass = 1; /* 2-pass disabled by default */
  94.  ULONG MaxMem = 1000000;
  95.  
  96.  #ifdef AZTEC_C             /* Disable Aztec C CTRL-C handling */
  97.  Enable_Abort = 0;
  98.  #endif
  99.  #ifdef __GNUC__            /* Modify GNU C CTRL-C handling */
  100.  signal(SIGINT, GCCAbortHandler);
  101.  #endif
  102.  
  103.  puts("ppm2AGA V1.3 written by Günther Röhrich.");
  104.  
  105.  /* remove the comments for beta versions */
  106. /*  puts("Preliminary version. DO NOT SPREAD IT!");  */
  107.  
  108.  
  109.  /* Open all the libraries we need */
  110.  
  111.  if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 33)))
  112.    PLError("Can't open intuition.library V33 or higher.\n");
  113.  
  114.  if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
  115.    PLError("Can't open graphics.library V33 or higher.\n");
  116.  
  117.  /* iffparse.library V37 works also with Kickstart 1.2/1.3 */
  118.  
  119.  if(!(IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library",36)))
  120.    PLError("Can't open iffparse.library V36 or higher.\n");
  121.  
  122.  if(argc < 3) PLUsage();
  123.  
  124.  for(i=3; i<argc; i++)
  125.  {
  126.    #ifndef __GNUC__
  127.    strupr(argv[i]);
  128.    #endif
  129.    if(!MYSTRNCMP(argv[i], "-HAM8", 5))
  130.    {
  131.      Mode = HAM8;
  132.      NumPlanes = 63;
  133.    }
  134.    else if(!MYSTRNCMP(argv[i], "-HAM6", 5))
  135.    {
  136.      Mode = HAM6;
  137.      NumPlanes = 15;
  138.    }
  139.    else if(!MYSTRNCMP(argv[i], "-CMAP", 5))
  140.    {
  141.      Mode = COLORMAP;
  142.      NumPlanes = (int)strtoul(&argv[i][5], NULL, 0);
  143.      if(NumPlanes < 1 || NumPlanes > 8)
  144.      PLError("Only 1 to 8 planes allowed.\n");
  145.    }
  146.    else if(!MYSTRNCMP(argv[i], "-M", 2))
  147.    {
  148.      MaxMem = strtoul(&argv[i][2], NULL, 0);
  149.    }
  150.    else if(!MYSTRNCMP(argv[i], "-FS", 3))
  151.    {
  152.      floyd = 1;
  153.    }
  154.    else if(!MYSTRNCMP(argv[i], "-E", 2))
  155.    {
  156.      ExactColor = 1;
  157.    }
  158.    else if(!MYSTRNCMP(argv[i], "-D", 2))
  159.    {
  160.      GfxEnable = 1;
  161.    }
  162.    else if(!MYSTRNCMP(argv[i], "-2", 2))
  163.    {
  164.      Pass = 0;
  165.    }
  166.    else if(!MYSTRNCMP(argv[i], "-VGA", 4))
  167.    {
  168.      VGAenable = 1;
  169.    }
  170.    else if(!MYSTRNCMP(argv[i], "-jpegAGA", 8))
  171.    {
  172.      jpegAGA = 1;
  173.    }
  174.    else PLUsage();
  175.    if( (jpegAGA == 1) && (Pass == 0 || Mode != HAM8)) PLUsage(); 
  176.  }    
  177.  
  178.  ILBMfile = argv[2];
  179.  if(Mode == HAM8 || Mode == HAM6) NumPlanes = NumPlanes + Pass;
  180.  Error = ppm2ilbm(argv[1], Mode, NumPlanes, MaxMem);
  181.  
  182.  /* if(Error) pm_message("Error, no picture created.\n"); */
  183.  
  184.  PLExit(Error);  
  185. }
  186.  
  187. void PLError(char *ErrorString)
  188. {
  189.  pm_message(ErrorString);
  190.  PLExit(10);
  191. }
  192.  
  193.  
  194.  
  195.  
  196. /* NOTE: if you want to implement a GUI you only have to */
  197. /* change the functions below, not the complete program  */
  198.  
  199.  
  200. /* this is called on exit */
  201.  
  202. void PLExit(int returnvalue)
  203. {
  204.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  205.  if(GfxBase)       CloseLibrary(GfxBase);
  206.  if(IFFParseBase)  CloseLibrary(IFFParseBase);
  207.  exit(returnvalue);
  208. }
  209.  
  210.  
  211. /* this is called to see if we must abort */
  212.  
  213. int AbortCheck(void)
  214. {
  215.  #ifndef __GNUC__
  216.  return SetSignal(0L,0L)&SIGBREAKF_CTRL_C;
  217.  #else
  218.  return GCCabort;
  219.  #endif 
  220. }
  221.  
  222.  
  223. /* this is called for progress reports */
  224. /* not called in this version */
  225.  
  226. void PLProgress(ULONG Value, ULONG MaxValue)
  227. {
  228.  /* we do nothing special right now */
  229.  printf("\015Progress: %5.2f%%", Value * 100.0 / (MaxValue + 1));
  230. }
  231.  
  232.  
  233. /* this is called when a message must be printed */
  234.  
  235. void pm_message(char* format, ... )
  236. {
  237.   va_list args;
  238.  
  239.   va_start( args, format );
  240.   vprintf(format, args );
  241.   va_end( args );
  242. }
  243.